﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using NetJsWire.Lite.Converters;
using Newtonsoft.Json;

namespace NetJsWire.Lite.Widgets.UI.Form
{
    [JsonObject( MemberSerialization = MemberSerialization.OptIn )]
    public class TimeFieldLW : ComboBoxLW
    {
        private const string DefaultInvalidText = "{value} is not a valid time";
        private const string DefaultMaxText = "The time in this field must be equal to or before {0}";
        private const string DefaultMinText = "The time in this field must be equal to or after {0}";

        public TimeFieldLW()
            : this( null )
        {
        }

        public TimeFieldLW( IContainer container )
            : base( container )
        {
            base.Xtype = "timefield";
            Increment = 15;
            InvalidText = DefaultInvalidText;
            MaxText = DefaultMaxText;
            MinText = DefaultMinText;
        }

        [DefaultValue( ( string ) null )]
        [JsonProperty( "altFormats", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "Multiple date formats separated by '|' to try when parsing a user input value and it doesn't match the defined format." )]
        public string AltFormats { get; set; }

        [DefaultValue( ( string ) null )]
        [JsonProperty( "format", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The default time format string which can be overriden for localization support. The format must be valid according to Date.parseDate (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time format try 'H:i' instead." )]
        public string Format { get; set; }

        [DefaultValue( 15 )]
        [JsonProperty( "increment", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The default time format string which can be overriden for localization support. The format must be valid according to Date.parseDate (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time format try 'H:i' instead." )]
        public int Increment { get; set; }

        [DefaultValue( DefaultInvalidText )]
        [JsonProperty( "invalidText", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The error text to display when the time in the field is invalid (defaults to '{value} is not a valid time')." )]
        public override string InvalidText { get; set; }

        [DefaultValue( DefaultMaxText )]
        [JsonProperty( "maxText", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The error text to display when the time is after maxValue (defaults to 'The time in this field must be equal to or before {0}')." )]
        public string MaxText { get; set; }

        [DefaultValue( ( string ) null )]
        [JsonProperty( "maxValue", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The maximum allowed time.\nCan be either a Javascript date object with a valid time value or a string time in a valid format." )]
        [JsonConverter( typeof( NotQuotedJsonStringConverter ) )]
        public string MaxValue { get; set; }

        [DefaultValue( DefaultMinText )]
        [JsonProperty( "minText", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The error text to display when the date in the cell is before minValue (defaults to 'The time in this field must be equal to or after {0}')." )]
        public string MinText { get; set; }

        [DefaultValue( ( string ) null )]
        [JsonProperty( "minValue", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        [Description( "The minimum allowed time.\nCan be either a Javascript date object with a valid time value or a string time in a valid format." )]
        [JsonConverter( typeof( NotQuotedJsonStringConverter ) )]
        public string MinValue { get; set; }
    }
}
